package com.yanxinim.cn.adapter;

import android.annotation.SuppressLint;
import android.content.Context;
import android.graphics.Color;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.yanxinim.cn.R;
import com.yanxinim.cn.bean.redpacket.BankCardBean;
import com.yanxinim.cn.bean.redpacket.MySubordinateInfo;
import com.yanxinim.cn.bean.redpacket.WithdrawRecordBean;
import com.yanxinim.cn.call.CustomOnItemClickListener;

import java.text.DecimalFormat;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

/**
 * @ClassName BankCardAdapter
 * @Description 提现记录列表适配器
 * @Author ChenXL
 * @Date 2021/5/25 19:57
 * @Version 1.0
 */
public class WithdrawRecordAdapter extends RecyclerView.Adapter<WithdrawRecordAdapter.ViewHolder>{

    List<WithdrawRecordBean> items = new ArrayList<>();

    private Context mContext;
    private LayoutInflater mInflater;

    public WithdrawRecordAdapter(Context context) {
        this.mContext = context;
        this.mInflater = LayoutInflater.from(context);
    }

    public void setItems(List<WithdrawRecordBean> items) {
        this.items = items;
    }
    public void addItems(List<WithdrawRecordBean> items) {
        this.items.addAll(items);
    }

    @NonNull
    @Override
    public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        return new ViewHolder(mInflater.inflate(R.layout.item_withdraw_record, parent, false));
    }

    @Override
    public void onBindViewHolder(@NonNull ViewHolder holder, final int position) {
        if (items.size() > position && items.get(position) != null) {
            WithdrawRecordBean bean = items.get(position);

            SimpleDateFormat sdf = new SimpleDateFormat("MM月dd日 HH:mm");
            String StrTime = sdf.format(new Date(bean.getCreateTime() * 1000L));
            holder.tvDate.setText(StrTime);
            String title = "";
            String symbol = "";
            DecimalFormat decimalFormat = new DecimalFormat("0.00");
            if (bean.getStatus() == -1){
                title = "提现失败";
                symbol = "+";

                holder.tvNumber.setTextColor(mContext.getResources().getColor(R.color.color_role5));
            }else if (bean.getStatus() == 1){
                title = "提现成功";
                symbol = "-";

                holder.tvNumber.setTextColor(mContext.getResources().getColor(R.color.green));
            }else {
                title = "审核中";
                symbol = "-";

                holder.tvNumber.setTextColor(mContext.getResources().getColor(R.color.blue));
            }
            holder.tvTitle.setText(title);
            holder.tvNumber.setText(symbol + decimalFormat.format(bean.getTotalFee()));
        }
    }

    @Override
    public int getItemCount() {
        return items == null ? 0 : items.size();
    }

    static class ViewHolder extends RecyclerView.ViewHolder {
        TextView tvTitle;
        TextView tvDate;
        TextView tvNumber;

        public ViewHolder(View view) {
            super(view);
            tvTitle = (TextView) view.findViewById(R.id.tvTitle);
            tvDate = (TextView) view.findViewById(R.id.tvDate);
            tvNumber = (TextView) view.findViewById(R.id.tvNumber);
        }
    }

}
